package server;
import java.util.Vector;
/**
 * This class represents a Resource - a logical unit that contains all the representations of a given image
 * @author yariv zur
 */
public class Resource {

	private String id, path;
	private Vector<Representation> reps;
	/**
	 * Constructor for the Resource class
	 * @param id - the resource id
	 */
	public Resource(String id){
		this.id = id;
		reps = new Vector<Representation>(0);
		this.path = ("photos/"+id);
	}
	/**
	 * Getter for the resource Id
	 * @return the Id
	 */
	public String getId(){
		return this.id;
	}
	/**
	 * Adds a new representation to the reps Vector and returns it
	 * @return the new representation added
	 */
	public Representation addRep(){
		Representation ans = new Representation (""+reps.size());
		reps.add(ans);
		return ans;
	}
	/**
	 * Getter for the resource server URI
	 * @return the path
	 */
	public String getPath(){
		return this.path;
	}
	/**
	 * Getter for the resource representations Vector
	 * @return the reps Vector
	 */
	public Vector<Representation> getReps(){
		return this.reps;
	}
	/**
	 * Search for a given Representation by its id, return it if found and null otherwise
	 * @return the requested Representation
	 */
	public Representation getRepresentation(String repId){
		Representation ans = null;
		synchronized(this){
			for(Representation rep:reps){
				if(rep.getId().equals(repId)){
					ans = rep;
					break;
				}
			}
		}
		return ans;
	}
}
